<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="100px">
      <el-form-item label="用户id" prop="userId">
        <el-input
          v-model="queryParams.userId"
          placeholder="用户id"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="用户昵称" prop="nickName">
        <el-input
          v-model="queryParams.nickName"
          placeholder="请输入用户昵称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="用户真实姓名" prop="realName">
        <el-input
          v-model="queryParams.realName"
          placeholder="请输入用户真实姓名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="手机号码" prop="phone">
        <el-input
          v-model="queryParams.phone"
          placeholder="请输入手机号码"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="身份证号码" prop="cardId">
        <el-input
          v-model="queryParams.cardId"
          placeholder="请输入身份证号码"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="身份认证" prop="isIdentity">
        <el-select v-model="queryParams.isIdentity" placeholder="请选择" clearable size="small">
          <el-option
            v-for="item in optionssfzt"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="职业认证" prop="isZyIdentity">
        <el-select v-model="queryParams.isZyIdentity" placeholder="请选择" clearable size="small">
          <el-option
            v-for="item in allOptionss"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="学历认证" prop="isIdentity">
        <el-select v-model="queryParams.isXlIdentity" placeholder="请选择" clearable size="small">
          <el-option
            v-for="item in allOptionss"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="婚姻认证" prop="isIdentity">
        <el-select v-model="queryParams.isHyIdentity" placeholder="请选择" clearable size="small">
          <el-option
            v-for="item in allOptionss"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="帐号状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择" clearable size="small">
          <el-option
            v-for="item in optionszhzt"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
      <!--<el-form-item label="推广人上级id" prop="spreadUid">
        <el-input
          v-model="queryParams.spreadUid"
          placeholder="请输入推广人上级id"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>-->
      <!--<el-form-item label="唯一邀请码" prop="invitationCode">
        <el-input
          v-model="queryParams.invitationCode"
          placeholder="请输入唯一邀请码"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>-->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <!--<el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
        >导出</el-button>
      </el-col>
    </el-row>-->

    <el-table  height="550" style="width: 100%" v-loading="loading" :data="userList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="用户ID" align="center" prop="userId" width="100" show-overflow-tooltip />
      <el-table-column label="用户昵称" align="center" prop="nickName" width="100" show-overflow-tooltip/>
      <el-table-column label="用户真实姓名" align="center" prop="realName" width="100" show-overflow-tooltip/>
      <!--<el-table-column label="用户类型" align="center" prop="userType" >
        <template slot-scope="scope">
          <span v-show="scope.row.userType==0">用户</span>
          <span v-show="scope.row.userType==1">商家</span>
        </template>
      </el-table-column>-->
      <el-table-column label="手机号码" align="center" prop="phone" width="180" show-overflow-tooltip/>
      <el-table-column label="用户性别" align="center" prop="sex" >
        <template slot-scope="scope">
          <span v-show="scope.row.sex==1">男</span>
          <span v-show="scope.row.sex==2">女</span>
        </template>
      </el-table-column>

      <el-table-column label="身份证号码" align="center" prop="cardId" width="100" show-overflow-tooltip/>
      <el-table-column label="身份证照正面" align="center" prop="cardPicZm" width="100"  >
        <template slot-scope="scope">
          <el-image
            style="width: 50px; height: 50px"
            :src="scope.row.cardPicZm"
            :preview-src-list="[scope.row.cardPicZm]">
          </el-image>
        </template>

      </el-table-column>
      <el-table-column label="身份证照反面" align="center" prop="cardPicFm" width="100"  >
        <template slot-scope="scope">
          <el-image
            style="width: 50px; height: 50px"
            :src="scope.row.cardPicFm"
            :preview-src-list="[scope.row.cardPicFm]">
          </el-image>
        </template>
      </el-table-column>
      <!--<el-table-column label="手持身份证照" align="center" prop="inHandCard" width="100" >
        <template slot-scope="scope">
          <el-image
            style="width: 50px; height: 50px"
            :src="scope.row.cardPicFm"
            :preview-src-list="[scope.row.cardPicFm]">
          </el-image>
        </template>
      </el-table-column>-->
      <el-table-column label="外籍证件号码" align="center" prop="zjh" width="100" show-overflow-tooltip/>
      <el-table-column label="外籍证件正面" align="center" prop="zjUrlZm" width="100"  >
        <template slot-scope="scope">
          <el-image
            style="width: 50px; height: 50px"
            :src="scope.row.zjUrlZm"
            :preview-src-list="[scope.row.zjUrlZm]">
          </el-image>
        </template>

      </el-table-column>
      <el-table-column label="外籍证件反面" align="center" prop="zjUrlFm" width="100"  >
        <template slot-scope="scope">
          <el-image
            style="width: 50px; height: 50px"
            :src="scope.row.zjUrlFm"
            :preview-src-list="[scope.row.zjUrlFm]">
          </el-image>
        </template>
      </el-table-column>
      <el-table-column label="手持身份证照" align="center" prop="inHandCard" width="100" >
        <template slot-scope="scope">
          <el-image
            style="width: 50px; height: 50px"
            :src="scope.row.cardPicFm"
            :preview-src-list="[scope.row.cardPicFm]">
          </el-image>
        </template>
      </el-table-column>
      <el-table-column label="身份认证状态" align="center" prop="isIdentity" width="100">
        <template slot-scope="scope">
          <span v-show="scope.row.isIdentity==0">未认证</span>
          <span v-show="scope.row.isIdentity==1">待认证</span>
          <span v-show="scope.row.isIdentity==2">已认证</span>
        </template>
      </el-table-column>
      <el-table-column label="头像地址" align="center" prop="txUrl" width="100" >
        <template slot-scope="scope">
          <el-image
            style="width: 50px; height: 50px"
            :src="scope.row.txUrl"
            :preview-src-list="[scope.row.txUrl]">
          </el-image>
        </template>
      </el-table-column>
      <el-table-column label="生日" align="center" prop="birthday"  width="100" show-overflow-tooltip>
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.birthday, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="帐号状态" align="center" prop="status" >
        <template slot-scope="scope">
          <span v-show="scope.row.status==0">正常</span>
          <span v-show="scope.row.status==1">停用</span>
          <span v-show="scope.row.status==2">注销</span>
        </template>
      </el-table-column>
      <!--<el-table-column label="注销时间" align="center" prop="cancelTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.cancelTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>-->
      <!--<el-table-column label="最后登录IP" align="center" prop="loginIp" width="180" show-overflow-tooltip />-->
      <!--<el-table-column label="最后登录时间" align="center" prop="loginDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.loginDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>-->
      <el-table-column label="创建时间" align="center" prop="createTime" width="100">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>

     <!-- <el-table-column label="推广人上级id" align="center" prop="spreadUid" width="180" show-overflow-tooltip/>-->
      <el-table-column label="省名称" align="center" prop="proName" width="100" show-overflow-tooltip/>
      <el-table-column label="市名称" align="center" prop="cityName" width="100" show-overflow-tooltip/>
      <el-table-column label="区名称" align="center" prop="areaName" width="100" show-overflow-tooltip/>
      <el-table-column label="用户余额" align="center" prop="nowMoney" width="100" show-overflow-tooltip/>
      <!--<el-table-column label="佣金金额" align="center" prop="brokeragePrice" width="180" show-overflow-tooltip/>-->
      <!--<el-table-column label="经度" align="center" prop="lng" width="180" show-overflow-tooltip/>-->
     <!--<el-table-column label="纬度" align="center" prop="lat" width="180" show-overflow-tooltip/>-->
      <!--<el-table-column label="唯一邀请码" align="center" prop="invitationCode" width="180" show-overflow-tooltip />-->
      <el-table-column label="会员等级" align="center" prop="isVip" >
        <template slot-scope="scope">
          <span v-show="scope.row.isVip==0">普通</span>
          <span v-show="scope.row.isVip==1">vip</span>
          <span v-show="scope.row.isVip==2">高级vip</span>
        </template>
      </el-table-column>
      <el-table-column label="vip到期时间" align="center" prop="vipExpireTime" width="100">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.vipExpireTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <!--<el-table-column label="备注" align="center" prop="remark" width="180" show-overflow-tooltip/>-->
      <el-table-column  fixed="right" width="150"  label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
          >修改</el-button>
          <!--<el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
          >删除</el-button>-->
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改app用户信息通用对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px"  >
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">

        <el-form-item label="身份认证状态" prop="isIdentity">

          <el-select style="width: 100%;" v-model="form.isIdentity" placeholder="请选择" clearable size="small">
            <el-option
              v-for="item in optionssfzt"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>

        </el-form-item>
        <el-form-item label="帐号状态">
          <el-select style="width: 100%;" v-model="form.status" placeholder="请选择" clearable size="small">
            <el-option
              v-for="item in optionszhzt"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="备注" prop="remark">
          <el-input style="width: 100%;" v-model="form.remark" placeholder="请输入备注" size="small"  />
        </el-form-item>
        <el-form-item label="会员等级" prop="isVip">

          <el-select style="width: 100%;" v-model="form.isVip" placeholder="请选择" clearable size="small">
            <el-option
              v-for="item in optionsvip"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>

        </el-form-item>
        <el-form-item label="vip到期时间" prop="vipExpireTime">
          <el-date-picker clearable size="small"
                          style="width: 100%;"
                          v-model="form.vipExpireTime"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="选择vip到期时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="院校名称" prop="remark">
          <el-input style="width: 100%;" v-model="form.xqqXb" placeholder="院校名称" size="small"  />
        </el-form-item>
        <el-form-item label="公职名称" prop="remark">
          <el-input style="width: 100%;" v-model="form.xqqGz" placeholder="公职名称" size="small"  />
        </el-form-item>
        <el-form-item label="离异时长" prop="remark">
          <el-input style="width: 100%;" v-model="form.xqqLl" placeholder="离异时长" size="small"  />
        </el-form-item>
        <el-form-item label="颜值得分" prop="remark">
          <el-input style="width: 100%;" v-model="form.xqqYz" placeholder="颜值得分" size="small"  />
        </el-form-item>
        <el-form-item label="职业名称" prop="remark">
          <el-input style="width: 100%;" v-model="form.xqqBl" placeholder="职业名称" size="small"  />
        </el-form-item>
        <el-form-item label="职业认证" prop="remark">
          <el-select v-model="form.isZyIdentity" style="width: 100%" placeholder="请选择" clearable size="small">
            <el-option
              v-for="item in allOptionss"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="学历认证" prop="remark">
          <el-select v-model="form.isXlIdentity" style="width: 100%" placeholder="请选择" clearable size="small">
            <el-option
              v-for="item in allOptionss"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="婚姻认证" prop="remark">
          <el-select v-model="form.isHyIdentity" style="width: 100%" placeholder="请选择" clearable size="small">
            <el-option
              v-for="item in allOptionss"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="用户相册" prop="" >
          <el-image
            v-for="item in form.userPicList"
            z-index="3002"
            v-show="item.ty==1"
            style="width: 100px; height: 100px;margin-left: 10px;margin-bottom: 10px"
            :src="item.picUrl"
            :preview-src-list="[item.picUrl]">
          </el-image>
        </el-form-item>
        <el-form-item label="职业认证-工牌" prop="" >
          <el-image
            v-for="item in form.userPicList"
            z-index="3002"
            v-show="item.ty==2"
            style="width: 100px; height: 100px;margin-left: 10px;margin-bottom: 10px"
            :src="item.picUrl"
            :preview-src-list="[item.picUrl]">
          </el-image>
        </el-form-item>
        <el-form-item label="职业认证-合同" prop="" >
          <el-image
            v-for="item in form.userPicList"
            z-index="3002"
            v-show="item.ty==3"
            style="width: 100px; height: 100px;margin-left: 10px;margin-bottom: 10px"
            :src="item.picUrl"
            :preview-src-list="[item.picUrl]">
          </el-image>
        </el-form-item>
        <el-form-item label="学历" prop="" >
          <el-image
            v-for="item in form.userPicList"
            z-index="3002"
            v-show="item.ty==4"
            style="width: 100px; height: 100px;margin-left: 10px;margin-bottom: 10px"
            :src="item.picUrl"
            :preview-src-list="[item.picUrl]">
          </el-image>
        </el-form-item>
        <el-form-item label="婚姻" prop="" >
          <el-image
            v-for="item in form.userPicList"
            z-index="3002"
            v-show="item.ty==5"

            style="width: 100px; height: 100px;margin-left: 10px;margin-bottom: 10px"
            :src="item.picUrl"
            :preview-src-list="[item.picUrl]">
          </el-image>
        </el-form-item>
      </el-form>

      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listUser, getUser, delUser, addUser, updateUser, exportUser } from "@/api/lanbangkeji/user/huiyuan";

export default {
  name: "User",
  components: {
  },
  data() {
    return {
      //账号状态 0=正常,1=停用 2=注销"
      optionszhzt:[
        {value:0,label:'正常'},
        {value:1,label:'停用'},
        {value:2,label:'注销'},
      ],
      //vip 0普通 1vip 2高级vip
      optionsvip:[
        {value:0,label:'普通'},
        {value:1,label:'vip '},
        {value:2,label:'高级vip'},
      ],
      //身份证 0未认证 1待认证 2已认证
      optionssfzt:[
        {value:0,label:'未认证'},
        {value:1,label:'待认证'},
        {value:2,label:'已认证'},
      ],
      allOptionss:[
        {value:0,label:'未认证'},
        {value:1,label:'待认证'},
        {value:2,label:'已认证'},
      ],
      //用户类型  0用户 1商家
      optionsyhlx:[
        {value:0,label:'用户'},
        {value:1,label:'商家'},
      ],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // app用户信息通用表格数据
      userList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userId: null,
        userName: null,
        nickName: null,
        realName: null,
        userType: null,
        phone: null,
        cardId: null,
        isIdentity: null,
        status: null,
        spreadUid: null,
        invitationCode: null,
        isVip: null,
        vipExpireTime: null,
        isZyIdentity: null,
        isXlIdentity: null,
        isHyIdentity:null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询app用户信息通用列表 */
    getList() {
      this.loading = true;
      listUser(this.queryParams).then(response => {
        this.userList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        userId: null,
        openId: null,
        userName: null,
        nickName: null,
        realName: null,
        userType: null,
        email: null,
        phone: null,
        sex: null,
        cardId: null,
        cardPicZm: null,
        cardPicFm: null,
        inHandCard: null,
        isIdentity: null,
        txUrl: null,
        password: null,
        birthday: null,
        status: 0,
        cancelTime: null,
        loginIp: null,
        loginDate: null,
        createTime: null,
        remark: null,
        spreadUid: null,
        proId: null,
        proName: null,
        cityId: null,
        cityName: null,
        areaId: null,
        areaName: null,
        nowMoney: null,
        brokeragePrice: null,
        lng: null,
        lat: null,
        invitationCode: null,
        isVip: null,
        vipExpireTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.userId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加app用户信息通用";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const userId = row.userId || this.ids
      getUser(userId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改app用户信息通用";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.userId != null) {
            updateUser(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addUser(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const userIds = row.userId || this.ids;
      this.$confirm('是否确认删除app用户信息通用编号为"' + userIds + '"的数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function() {
        return delUser(userIds);
      }).then(() => {
        this.getList();
        this.msgSuccess("删除成功");
      })
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有app用户信息通用数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function() {
        return exportUser(queryParams);
      }).then(response => {
        this.download(response.msg);
      })
    }
  }
};
</script>
<style>
/*.el-image-viewer__mask {*/
/*  z-index: 3000!important;*/
/*}*/
.el-image-viewer__canvas {
  z-index: 3001 !important;
}
</style>
